import { createRouter, createWebHistory } from 'vue-router';
import test from '../view/test/index.vue';
const routes = [
   {
    path: '/',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '/',
        component: () => import('../view/home/index.vue')
      }
    ]
   },
  {
    path: '/system',
    component:  () => import('@/layout/index.vue'),
    children: [
      {
        path: 'user',
        component: () => import('@/view/user/index.vue')
      }
    ]
  },
  {
    path: '/test',
    component: test
  },  
  {
    path: '/login',
    component: () => import('@/view/login/index.vue'),
  },
  {
    path: '/system',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: 'role',
        component: () => import('@/view/role/index.vue')
      }
    ]
  },  
  {
    path: '/system',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: 'menu',
        component: () => import('@/view/menu/index.vue')
      }
    ]
  },  
];

const router = createRouter({
  history: createWebHistory(),
  routes
});
router.beforeEach((to,from,next)=>{ 
  if(localStorage.getItem('username') ===null && to.path !=='/login'){
    router.push('/login')
   }
   else{
    next()
   }

})
export default router;